package com.wk.rabbit;

import com.wk.entity.MailBean;
import com.wk.util.MailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 王珂
 * @date 2020/7/20 23:51
 */
@Component
@Slf4j
@RabbitListener(queuesToDeclare = @Queue("hello"))
public class consumer {
    private static int count=0;

    @Autowired
    private MailUtil mailUtil;

    @RabbitHandler
    public void sendEmail(String msg){
        MailBean mailBean = new MailBean();
        mailBean.setSubject("极限云上线测试");
        mailBean.setText(msg);
        //发送邮件
        mailUtil.sendMail();
        log.info("发送邮件"+count++);
    }
}
